package com.yt.order.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yt.common.constant.Result;
import com.yt.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.yt.order.models.service.IDispatchRuleLogService;
import com.yt.order.models.bo.DispatchRuleLogBO;
import com.yt.order.models.dto.DispatchRuleLogDTO;

/**
 * 规则执行日志表控制器
 *
 * @author zhou
 * @Date 2025-09-14 10:05:29
 */

@RestController
@RequestMapping("/api/dispatchRuleLog")
@Slf4j
@Api(value = "DispatchRuleLogApiController",tags = "规则执行日志表Api接口")
public class DispatchRuleLogApiController {

    @DubboReference
    private IDispatchRuleLogService dispatchRuleLogService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<DispatchRuleLogDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        DispatchRuleLogDTO dto = dispatchRuleLogService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "规则执行日志表列表",notes = "规则执行日志表列表")
    @PostMapping("/queryPageList")
    public Result<Page<DispatchRuleLogDTO>> queryPageList(DispatchRuleLogBO bo){
        Wrapper<DispatchRuleLogDTO> wrapper = new EntityWrapper<>();
        if (bo.getStartDate() != null){
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null){
            wrapper.le("create_time", bo.getEndDate());

        }
        Page<DispatchRuleLogDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = dispatchRuleLogService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
